<template>
  <div>
    <el-dialog
      :title="title"
      width="90%"
      :visible.sync="isProduct"
      :close-on-click-modal="false"
      @close="add_order_close('ruleForm')"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-row style="margin-bottom: 25px">
          <el-col :span="24">
            <span style="font-size: 20px">当前订单审核流程：</span>
            <div
              v-for="(item, index) in AuditList"
              :key="item.id"
              style="display: inline; margin-left: 15px"
            >
              <span
                style="color: #e71f11; font-size: 22px"
                v-if="item.status == 1"
                >{{ index + 1 }}:{{ item.audit_name }}</span
              >
            </div>
          </el-col>
        </el-row>
        <div class="list_order">
          <div class="lis">
            <el-form-item label="订单号" prop="order_number">
              <el-input v-model="ruleForm.order_number" disabled></el-input>
            </el-form-item>
          </div>
          <!-- <div class="lis">
            <el-form-item label="流水号" prop="serial_number">
              <el-input
                v-model="ruleForm.serial_number"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div> -->
          <div class="lis">
            <el-form-item label="下单日期" prop="order_date">
              <el-date-picker
                v-model="ruleForm.order_date"
                :disabled="disableds"
                type="date"
                format="yyyy 年 MM 月 dd 日"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="交货日期" prop="delivery_date">
              <el-date-picker
                v-model="ruleForm.delivery_date"
                :disabled="disableds"
                type="date"
                format="yyyy 年 MM 月 dd 日"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="业务员">
              <el-select
                filterable
                v-model="ruleForm.account_executive_id"
                :disabled="disableds"
                placeholder="请选择业务员"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in EmployeeList"
                  :key="index"
                  :label="item.company_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="经销商" prop="customer_id">
              <el-select
                filterable
                v-model="ruleForm.customer_id"
                :disabled="disableds"
                placeholder="请选择经销商"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in CustomerList"
                  :key="index"
                  :label="item.customer_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- <div class="lis">
            <el-form-item label="业主地址">
              <el-input
                v-model="ruleForm.customer_name"
                type="text"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="业主电话">
              <el-input
                v-model="ruleForm.customer_phone"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div> -->
          <div class="lis">
            <el-form-item label="紧急程度" prop="emergency_procedure">
              <el-radio-group
                v-model="ruleForm.emergency_procedure"
                :disabled="disableds"
              >
                <el-radio :label="1">普通</el-radio>
                <el-radio :label="2">紧急</el-radio>
                <el-radio :label="3">十万火急</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>

          <div class="lis">
            <el-form-item label="是否补录">
              <el-radio-group
                v-model="ruleForm.is_replenishment"
                :disabled="disableds"
              >
                <el-radio :label="1">是</el-radio>
                <el-radio :label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <!-- <div class="lis">
            <el-form-item label="是否发货">
              <el-radio-group v-model="ruleForm.is_fahuo" :disabled="disableds">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div> -->
          <div class="lis">
            <el-form-item label="是否备货" prop="is_stock_up">
              <el-radio-group
                v-model="ruleForm.is_stock_up"
                :disabled="disableds"
              >
                <el-radio :label="1">是</el-radio>
                <el-radio :label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <div class="lis" v-if="type != 'purchase_status'">
            <el-form-item label="已收款">
              <el-input-number
                :disabled="disableds"
                v-model="ruleForm.received"
                type="number"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="lis" v-if="type != 'purchase_status'">
            <el-form-item label="应收款">
              <el-input-number
                :disabled="disableds"
                v-model="ruleForm.receivables"
                type="number"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="折扣">
              <el-input-number
                :disabled="disableds"
                v-model="ruleForm.discount"
                :min="0"
                style="max-width: 100%; width: 100%"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="支付方式">
              <el-select
                filterable
                clearable
                v-model="ruleForm.pay_type"
                :disabled="disableds"
                placeholder="请选择支付方式"
                style="width: 100%"
              >
                <el-option label="现结" value="现结"> </el-option>
                <el-option label="微信" value="微信"> </el-option>
                <el-option label="支付宝" value="支付宝"> </el-option>
                <el-option label="信用卡" value="信用卡"> </el-option>
                <el-option label="后付" value="后付"> </el-option>
                <el-option label="到付" value="  到付"> </el-option>
                <el-option label="月结" value="月结"> </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="发货仓库">
              <el-select
                v-model="ruleForm.warehouse_id"
                :disabled="disableds"
                clearable
                placeholder="请选择仓库"
                @change="ban_warehouse"
                style="width: 48%"
              >
                <el-option
                  v-for="(item, index) in cangkulists"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="ruleForm.goods_shelf_id"
                :disabled="disableds"
                filterable
                clearable
                placeholder="请选择货架"
                style="width: 48%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in huojialist"
                  :key="index"
                  :label="item.name"
                  :value="item.goods_shelf_id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis">
            <el-form-item label="经销商地址">
              <el-input
                v-model="ruleForm.logistics_company"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div>
          <!-- <div class="lis">
            <el-form-item label="备注">
              <el-input
                :disabled="disableds_product"
                v-model="ruleForm.remark"
                :autosize="{ minRows: 2, maxRows: 4 }"
                type="textarea"
              ></el-input>
            </el-form-item>
          </div> -->
        </div>
        <div v-for="(item, indexs) in semi_product" :key="indexs">
          <div class="list_orders" v-if="item.is_del == 2">
            <div class="lis">
              <el-form-item label="产品类型">
                <el-select
                  filterable
                  v-model="item.type_id"
                  :disabled="disableds_product"
                  placeholder="请选择产品"
                  style="width: 100%"
                  @change="product_id_type(indexs, item.type_id)"
                >
                  <el-option label="产品" :value="1"> </el-option>
                  <el-option label="组件" :value="2"> </el-option>
                  <el-option label="外购" :value="3"> </el-option>
                </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="产品">
                <el-select
                  filterable
                  clearable
                  v-model="item.product_id"
                  :disabled="disableds_product"
                  placeholder="请选择产品"
                  style="width: 100%"
                  @change="product_id_change(item.product_id, indexs)"
                >
                  <el-option
                    v-for="(ite, index) in item.productList"
                    :key="index"
                    :label="ite.product_name"
                    :value="ite.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="型号">
                <el-select
                  filterable
                  clearable
                  :disabled="disableds_product"
                  v-model="item.model_number_id"
                  @change="
                    model_number_id_change(
                      item.product_id,
                      item.model_number_id,
                      indexs
                    )
                  "
                  placeholder="请选择型号"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(ite, index) in item.ModelNumberList"
                    :key="index"
                    :label="ite.model_number"
                    :value="ite.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div>

            <div class="lis">
              <el-form-item label="规格">
                <el-select
                  filterable
                  clearable
                  v-model="item.specification_id"
                  :disabled="disableds_product"
                  placeholder="请选择规格"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(ite, index) in item.SpecificationList"
                    :key="index"
                    :label="ite.specification"
                    :value="ite.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="尺寸">
                <el-input
                  v-model="item.work_size"
                  :disabled="disableds_product"
                ></el-input>
              </el-form-item>
            </div>
            <!-- <div class="lis">
                <el-form-item label="方向">
                  <el-input
                    v-model="item.direction"
                    :disabled="disableds_product"
                  ></el-input>
                </el-form-item>
              </div> -->
            <!-- <div class="lis">
              <el-form-item label="加减方式">
                <el-input
                  v-model="item.addition_subtraction"
                  :disabled="disableds_product"
                ></el-input>
              </el-form-item>
            </div> -->
            <div class="lis">
              <el-form-item label="颜色">
                <el-select
                  @change="
                    yanse_change(item.ColorList, indexs, item.color_id, 1)
                  "
                  clearable
                  filterable
                  allow-create
                  v-model="item.color_id"
                  :disabled="disableds_product"
                  placeholder="请选择颜色"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in item.ColorList"
                    :key="index"
                    :label="item.color"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <!-- <div class="lis">
              <el-form-item label="品牌">
                <el-input
                  v-model="item.brand"
                  :disabled="disableds_product"
                ></el-input>
              </el-form-item>
            </div> -->
            <div class="lis" v-if="item.type_id == 1">
              <el-form-item label="是否拆分">
                <el-checkbox
                  v-model="item.is_split"
                  :true-label="1"
                  :false-label="2"
                  @change="
                    is_split_change(item.is_split, indexs, item.product_id)
                  "
                ></el-checkbox>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="单价">
                <el-input-number
                  v-model="item.price"
                  :precision="2"
                  :disabled="disableds_product"
                ></el-input-number>
              </el-form-item>
            </div>
            <!-- <div class="lis">
              <el-form-item label="系数">
                <el-input-number
                  v-model="item.xishu"
                  :precision="2"
                  :disabled="disableds_product"
                ></el-input-number>
              </el-form-item>
            </div> -->
            <div class="lis" v-if="item.is_split == 2">
              <el-form-item label="使用库存">
                <el-checkbox
                  :disabled="disableds_product || item.kucun_num < item.num"
                  v-model="item.is_kucun"
                  :true-label="1"
                  :false-label="2"
                ></el-checkbox
                >（{{ item.kucun_num }}）
              </el-form-item>
            </div>

            <div class="lis">
              <el-form-item label="数量">
                <el-input-number
                  :disabled="disableds_product"
                  v-model="item.num"
                  type="number"
                ></el-input-number>
              </el-form-item>
            </div>
            <!-- <div class="lis">
              <el-form-item label="床头柜备注">
               
                <el-input
                  v-model="item.chuangtougui_remark"
                  :disabled="disableds_product"
                ></el-input>
              </el-form-item>
            </div> -->
            <!-- <div class="lis">
              <el-form-item label="床边备注">
                <el-input
                  v-model="item.chuangbian_remark"
                  :disabled="disableds_product"
                ></el-input>
              </el-form-item>
            </div> -->

            <div class="lis">
              <el-form-item label="产品备注">
                <el-input
                  class="bei_zhu_style"
                  :disabled="disableds_product"
                  v-model="item.remark"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  type="textarea"
                ></el-input>
              </el-form-item>
            </div>
            <div class="lis">
              <el-button
                :disabled="disableds_product"
                @click="del_cailiao(indexs)"
                type="primary"
                v-if="indexs > 0"
                >删除</el-button
              >
            </div>
          </div>
          <el-divider
            content-position="center"
            v-if="item.pid_list.length > 0 && item.is_split == 1"
            >拆分组件</el-divider
          >
          <div
            v-if="item.pid_list.length > 0 && item.is_split == 1"
            style="
              background: #f5f7fa;
              border-top: 1px solid #ebeef5;
              padding: 10px;
              box-sizing: border-box;
            "
          >
            <div
              class="list_order"
              v-for="(item_pid, index_pid) in item.pid_list"
              :key="index_pid"
            >
              <div class="lis">
                <el-form-item :label="item_pid.model_name">
                  <el-select
                    filterable
                    clearable
                    :disabled="disableds_product"
                    v-model="item_pid.product_id"
                    placeholder="请选择产品"
                    style="width: 100%"
                    @change="
                      get_InventoryCounts_pid(
                        item_pid.productList,
                        item_pid.product_id,
                        indexs,
                        index_pid
                      )
                    "
                  >
                    <el-option
                      v-for="(ite, index) in item_pid.productList"
                      :key="index"
                      :label="ite.product_name"
                      :value="ite.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
              <!-- <div class="lis">
                <el-form-item label="型号">
                  <el-select
                    filterable
                    clearable
                    :disabled="disableds_product"
                    v-model="item_pid.model_number_id"
                    @change="
                      model_number_id_change_pid(
                        item_pid.product_id,
                        item_pid.model_number_id,
                        indexs,
                        index_pid
                      )
                    "
                    placeholder="请选择型号"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="(ite, index) in item_pid.ModelNumberList"
                      :key="index"
                      :label="ite.model_number"
                      :value="ite.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div> -->
              <!-- <div class="lis">
                <el-form-item label="方向">
                  <el-input
                    v-model="item_pid.direction"
                    :disabled="disableds_product"
                  ></el-input>
                </el-form-item>
              </div>
              <div class="lis">
                <el-form-item label="加减方式">
                  <el-input
                    v-model="item_pid.addition_subtraction"
                    :disabled="disableds_product"
                  ></el-input>
                </el-form-item>
              </div>
              <div class="lis">
                <el-form-item label="品牌">
                  <el-input
                    v-model="item_pid.brand"
                    :disabled="disableds_product"
                  ></el-input>
                </el-form-item>
              </div>
              

              <div class="lis">
                <el-form-item label="规格">
                  <el-select
                    @change="get_InventoryCounts_pid(indexs, index_pid)"
                    filterable
                    clearable
                    v-model="item_pid.specification_id"
                    :disabled="disableds_product"
                    placeholder="请选择规格"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="(ite, index) in item_pid.SpecificationList"
                      :key="index"
                      :label="ite.specification"
                      :value="ite.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
              <div class="lis">
                <el-form-item label="颜色">
                  <el-select
                    @change="
                      yanse_change_pid(
                        item_pid.ColorList,indexs,index_pid,item_pid.color_id
                      )
                    "
                    clearable
                    filterable
                    allow-create
                    v-model="item_pid.color_id"
                    :disabled="disableds_product"
                    placeholder="请选择颜色"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="(item, index) in item_pid.ColorList"
                      :key="index"
                      :label="item.color"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
              <div class="lis">
                <el-form-item label="尺寸">
                  <el-input
                    v-model="item_pid.work_size"
                    :disabled="disableds_product"
                  ></el-input>
                </el-form-item>
              </div>
               <div class="lis">
                <el-form-item label="库存">
                  <el-input
                    v-model="item_pid.kucun_num"
                    type="text"
                    disabled
                  ></el-input>
                </el-form-item>
              </div> -->
              <div class="lis">
                <el-form-item label="是否需要">
                  <el-checkbox
                    :disabled="disableds_product"
                    v-model="item_pid.is_needed"
                    :true-label="1"
                    :false-label="2"
                  ></el-checkbox>
                </el-form-item>
              </div>
              <div class="lis">
                <el-form-item label="使用库存">
                  <el-checkbox
                    :disabled="
                      disableds_product || item_pid.kucun_num < item_pid.num
                    "
                    v-model="item_pid.is_kucun"
                    :true-label="1"
                    :false-label="2"
                  ></el-checkbox
                  >（{{ item_pid.kucun_num }}）
                </el-form-item>
              </div>

              <div class="lis">
                <el-form-item label="数量">
                  <el-input-number
                    :disabled="disableds_product"
                    v-model="item_pid.num"
                    type="number"
                  ></el-input-number>
                </el-form-item>
              </div>
              <div class="lis">
                <el-form-item label="产品备注">
                  <el-input
                    class="bei_zhu_style"
                    :disabled="disableds_product"
                    v-model="item_pid.remark"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                  ></el-input>
                </el-form-item>
              </div>
            </div>
          </div>
        </div>

        <el-button
          @click="add_cailiao"
          v-if="type != 'purchase_status'"
          style="display: block; margin: 0 auto; margin-top: 10px"
          type="primary"
          >新增产品</el-button
        >
      </el-form>
      <span
        slot="footer"
        class="dialog-footer"
        v-if="type == 'set_order' || type == 'add_order'"
      >
        <el-button type="primary" size="small" style="margin-right: 10px"
          >取 消</el-button
        >
        <el-button
          @click="submitadds('ruleForm')"
          type="primary"
          :loading="loading_btn"
          size="small"
        >
          确认</el-button
        >
      </span>

      <span slot="footer" class="dialog-footer" v-if="type == 'info_status'">
        <el-button
          @click="submitadds('ruleForm')"
          type="primary"
          :loading="loading_btn"
          size="small"
        >
          通过</el-button
        >
      </span>
      <span
        slot="footer"
        class="dialog-footer"
        v-if="type == 'purchase_status'"
      >
        <el-button
          @click="submitadds('ruleForm')"
          type="primary"
          :loading="loading_btn"
          size="small"
        >
          通过</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getYeWuYuanList,
  getOrderAuditFlow,
  automaticGenerationOrderNumber,
  automaticGenerationSerialNumber,
  getProductList,
  getModelNumberList,
  getProductColorList,
  getSpecificationList,
  createOrder,
  getCustomerList,
  getWarehouseList,
  getInventoryCount,
  auditOrder,
  alertOrder,
  createColor,
} from "@/api/product/index";
export default {
  data() {
    return {
      type: "",
      directionList: [
        {
          name: "左",
        },
        {
          name: "右",
        },
        {
          name: "无",
        },
      ],
      isProduct: false,
      disableds_product: false,
      role_name: this.$store.getters.userInfo.role_name,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      formatterTime(row, column) {
        let data = row[column.property];
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
      },
      title: "",
      AuditList: [],
      CustomerList: [],
      cangkulist: [],
      huojialist: [],
      disableds: false,
      loading_btn: false,
      ruleForm: {
        pay_type: "",
        discount: 0,
        is_fahuo: 2,
        warehouse_id: "",
        terminal_customer: "",
        goods_shelf_id: "",
        serial_number: "",
        order_number: "",
        order_date: "",
        delivery_date: "",
        account_executive_id: "",
        account_executive: "",
        customer_id: "",
        customer: "",
        customer_name: "",
        customer_phone: "",
        received: "",
        emergency_procedure: 1,
        is_replenishment: 2,
        is_stock_up: 2,
        receivables: "",
        remark: "",
        yukuan: "",
        id: "",
        logistics_company: "",
        semi_product: [],
      },
      semi_product: [],
      rules: {
        terminal_customer: [
          { required: true, message: "请输入终端客户", trigger: "blur" },
        ],
        // account_executive_id: [
        //   { required: true, message: "请选择业务员", trigger: "blur" },
        // ],
        warehouse_id: [
          { required: true, message: "请选择仓库", trigger: "blur" },
        ],
        goods_shelf_id: [
          { required: true, message: "请选择货架", trigger: "blur" },
        ],
        specification_id: [
          {
            required: true,
            message: "请选择规格",
            trigger: "blur",
          },
        ],
        order_number: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        order_date: [
          {
            required: true,
            message: "请选择下单日期",
            trigger: "blur",
          },
        ],
        delivery_date: [
          {
            required: true,
            message: "请选择交货日期",
            trigger: "blur",
          },
        ],
        account_executive_id: [
          {
            required: true,
            message: "请选择员工",
            trigger: "blur",
          },
        ],
        product_id: [
          {
            required: true,
            message: "请选择产品",
            trigger: "blur",
          },
        ],
        model_number_id: [
          {
            required: true,
            message: "请选择型号",
            trigger: "blur",
          },
        ],
        color_id: [
          {
            required: true,
            message: "请选择颜色",
            trigger: "blur",
          },
        ],
        size: [
          {
            required: true,
            message: "请选择规格",
            trigger: "blur",
          },
        ],
        direction: [
          {
            required: true,
            message: "请输入产品方向",
            trigger: "blur",
          },
        ],
        customer_id: [
          {
            required: true,
            message: "请选择经销商",
            trigger: "blur",
          },
        ],
        emergency_procedure: [
          {
            required: true,
            message: "请选择紧急程度",
            trigger: "blur",
          },
        ],
        is_stock_up: [
          {
            required: true,
            message: "是否备货",
            trigger: "blur",
          },
        ],
        receivables: [
          {
            required: true,
            message: "请输入应收款金额",
            trigger: "blur",
          },
        ],
      },
      productList: [],
      cangkulists: [],
      huojialist: [],
      EmployeeList: [],
      role_name: this.$store.getters.userInfo.role_name,
      role_id: "",
      productList_remark: [],
    };
  },
  mounted() {
    if (this.role_name === "经销商") {
      this.role_id = this.$store.getters.userInfo.role_id;
    }
    console.log(this.$store.getters);
  },
  watch: {
    "ruleForm.warehouse_id"(news, olds) {
      if (news) {
        this.ban_warehouse(news);
      }
    },
  },
  methods: {
    is_split_change(is_split, index, pid) {
      if (is_split == 2) {
        return false;
      }

      this.semi_product[index].pid_list = [];

      const model_list = [
        { model_name: "床头", id: 1 },
        { model_name: "床板", id: 3 },
        { model_name: "床帮", id: 2 },
        { model_name: "床头柜", id: 4 },
        { model_name: "配件箱", id: 5 },
      ];

      const templateObj = {
        id: "",
        model_name: "",
        productList: [],
        ModelNumberList: [],
        kucun_num: 0,
        is_kucun: 2,
        is_split: 2,
        pid: "",
        product_id: "",
        is_needed: 1,
        type_id: "",
        price: 0,
        xishu: 1,
        model_number_id: "",
        num: 1,
        remark: "",
      };

      const promises = model_list.map((item) => {
        const obj = {
          is_split,
          pid,
          model_id: item.id,
          is_simple: 1,
        };

        return getProductList(obj)
          .then((res) => {
            const newObj = {
              ...templateObj,
              model_name: item.model_name,
              productList: res.data,
            };
            return newObj;
          })
          .catch((error) => {
            console.error(
              `Error fetching product list for model ${item.model_name}:`,
              error
            );
            return null; // 返回 null 表示该条目失败
          });
      });

      Promise.all(promises)
        .then((results) => {
          // 过滤掉失败的请求结果
          const filteredResults = results.filter((result) => result !== null);

          // 按照 model_list 的顺序排序
          const sortedResults = filteredResults.sort((a, b) => {
            const aIndex = model_list.findIndex(
              (model) => model.model_name === a.model_name
            );
            const bIndex = model_list.findIndex(
              (model) => model.model_name === b.model_name
            );
            return aIndex - bIndex;
          });

          sortedResults.forEach((result) => {
            this.semi_product[index].pid_list.push(result);
          });
        })
        .catch((error) => {
          console.error("Error processing all product lists:", error);
        });
    },
    yanse_change(items, index, colorId) {
      // 检查 items 是否为空或 colorId 是否为 undefined 或 null
      if (colorId == null) {
        return;
      }
      if (!items || items.length === 0) {
        this.create_Color(colorId, index);
      } else {
        const itemIds = new Set(items.map((item) => item.id));
        // 检查 colorId 是否存在于 itemIds 中
        if (!itemIds.has(colorId)) {
          this.create_Color(colorId, index);
        }
      }
      // 使用 Set 提高查找效率
    },
    yanse_change_pid(items, index, index_pid, colorId) {
      // 检查 items 是否为空或 colorId 是否为 undefined 或 null
      if (colorId == null) {
        return;
      }
      if (!items || items.length === 0) {
        this.create_Color(colorId, index);
      } else {
        const itemIds = new Set(items.map((item) => item.id));
        // 检查 colorId 是否存在于 itemIds 中
        if (!itemIds.has(colorId)) {
          this.create_Color_pid(colorId, index, index_pid);
        }
      }
      // 使用 Set 提高查找效率
    },
    create_Color_pid(val, index, index_pid) {
      let lists = [];
      let list = [];
      list.push(val);
      lists.push(this.semi_product[index].pid_list[index_pid].product_id);
      let obj = {
        product_ids: lists,
        color_names: list,
      };
      createColor(obj).then((res) => {
        if (res.code == 200) {
          let lengths = this.semi_product[index].ColorList.length;
          this.$set(this.semi_product[index].ColorList, lengths, {
            id: res.data[0],
            color: val,
          });
          this.get_produccolor_pids(
            this.semi_product[index].pid_list[index_pid].product_id,
            index,
            index_pid,
            val
          );
        }
      });
    },
    create_Color(val, index) {
      let lists = [];
      let list = [];
      list.push(val);
      lists.push(this.semi_product[index].product_id);
      let obj = {
        product_ids: lists,
        color_names: list,
      };
      createColor(obj).then((res) => {
        if (res.code == 200) {
          let lengths = this.semi_product[index].ColorList.length;
          this.$set(this.semi_product[index].ColorList, lengths, {
            id: res.data[0],
            color: val,
          });
          this.get_produccolor(this.semi_product[index].product_id, index, val);
        }
      });
    },
    set_order(row, String) {
      this.getEmpl();
      // 审核流程
      this.get_OrderAuditList();
      // 产品
      this.getCustomer();
      this.semi_product = [];

      getWarehouseList().then((res) => {
        if (res.code == 200) {
          this.cangkulists = res.data.data;
          let {
            pay_type,
            discount,
            is_fahuo,
            warehouse_id,
            terminal_customer,
            goods_shelf_id,
            serial_number,
            order_number,
            order_date,
            delivery_date,
            account_executive_id,
            account_executive,
            customer_id,
            customer,
            customer_name,
            customer_phone,
            received,
            emergency_procedure,
            is_replenishment,
            is_stock_up,
            receivables,
            remark,
            yukuan,
            id,
            logistics_company,
          } = row;
          this.ruleForm = {
            pay_type,
            discount,
            is_fahuo,
            warehouse_id,
            terminal_customer,
            goods_shelf_id,
            serial_number,
            order_number,
            order_date,
            delivery_date,
            account_executive_id,
            account_executive,
            customer_id,
            customer,
            customer_name,
            customer_phone,
            received,
            emergency_procedure,
            is_replenishment,
            is_stock_up,
            receivables,
            remark,
            yukuan,
            id,
            logistics_company,
            semi_product: [],
          };
        }
      });
      this.isProduct = true;
      this.type = String;
      if (String == "info_status") {
        this.title = "信息审核";
      }
      if (String == "purchase_status") {
        this.title = "采购审核";
        // this.disableds = true;
        // this.disableds_product = true;
      }
      if (String == "set_order") {
        this.title = "修改订单";
        this.disableds_product = true;
      }
      this.set_orders(row);
    },
    set_pidlist(pids, row) {
      let pid_list = [];

      let model_list = [
        {
          model_name: "床头",
          id: 1,
        },

        {
          model_name: "床帮",
          id: 2,
        },
        {
          model_name: "床板",
          id: 3,
        },
        {
          model_name: "床头柜",
          id: 4,
        },
        {
          model_name: "配件箱",
          id: 5,
        },
      ];

      row.forEach((item) => {
        // const get_ProductList = getProductList({
        //   type_id: item.type_id,
        //   is_simple: 1,
        // });
        const get_ProductList_pid = getProductList({
          is_simple: 1,
          pid: pids,
        });
        const get_ModelNumberList = getModelNumberList({
          product_id: item.product_id,
          field_list: "id,model_number",
          is_dropdown: 1,
        });
        // let objs = {
        //   product_id: item.product_id,
        //   model_number_id: item.model_number_id,
        // };
        // const get_SpecificationList = getSpecificationList(objs);
        let obj_kucun = {
          product_id: item.product_id,
          model_number_id: item.model_number_id,
          specification_id: item.specification_id,
          color_id: item.color_id,
          // warehouse_id: this.ruleForm.warehouse_id,
          // goods_shelf_id: this.ruleForm.goods_shelf_id
        };
        const get_InventoryCount = getInventoryCount(obj_kucun);
        Promise.all([
          get_ProductList_pid,
          get_ModelNumberList,
          // get_SpecificationList,
          get_InventoryCount,
        ]).then((results) => {
          const [
            ProductList_pids,
            ModelNumberLists,
            // getSpecificationLists,
            // getColorList,
            kucun_nums,
          ] = results;
          if (
            ProductList_pids.code === 200 &&
            ModelNumberLists.code === 200 &&
            // getSpecificationLists.code === 200 &&
            // getColorList.code === 200 &&
            kucun_nums.code === 200
          ) {
            let arry = [];
            ProductList_pids.data.forEach((item_pid) => {
              arry.push(item_pid);
            });

            var model_names = "";
            if (item.product.model_id == 1) {
              model_names = "床头";
            }
            if (item.product.model_id == 2) {
              model_names = "床帮";
            }
            if (item.product.model_id == 3) {
              model_names = "床板";
            }
            if (item.product.model_id == 4) {
              model_names = "床头柜";
            }
            if (item.product.model_id == 5) {
              model_names = "配件箱";
            }

            let obj = {
              id: item.id,
              model_id: item.product ? item.product.model_id : "",
              model_name: model_names,
              productList: arry,
              is_needed: item.is_needed,
              price: item.price,
              xishu: item.xishu,
              ModelNumberList: ModelNumberLists.data.data,
              // SpecificationList: getSpecificationLists.data.data,
              // ColorList: getColorList.data,
              kucun_num: kucun_nums.data,
              is_kucun: item.is_kucun,
              pid: item.product_id,
              is_split: item.is_split,
              type_id: item.type_id,
              product_id: item.product_id ? item.product_id : "",
              model_number_id: item.model_number_id,
              // specification_id: item.specification_id,
              // color_id: item.color_id,
              // direction: item.direction,
              num: item.num,
              // work_size: item.work_size,
              // addition_subtraction: item.addition_subtraction,
              // brand:item.brand,
              // is_replenishment: item.is_replenishment,
              remark: item.remark,
              // is_del: item.is_del,
            };
            pid_list.push(obj);
          }
        });
      });
      return pid_list;
    },
    set_orders(row) {
      this.semi_product = [];
      row.order_second.forEach((item) => {
        const get_ProductList = getProductList({
          type_id: item.type_id,
          is_simple: 1,
        });
        const get_ModelNumberList = getModelNumberList({
          product_id: item.product_id,
          field_list: "id,model_number",
          is_dropdown: 1,
        });
        let objs = {
          product_id: item.product_id,
          model_number_id: item.model_number_id,
        };
        const get_SpecificationList = getSpecificationList(objs);

        const get_ProductColorList = getProductColorList({
          product_id: item.product_id,
        });
        // const get_ProductList_pid = getProductList({
        //     is_simple: item.is_simple,
        //     pid: item.pid,
        // });

        let obj_kucun = {
          product_id: item.product_id,
          model_number_id: item.model_number_id,
          specification_id: item.specification_id,
          color_id: item.color_id,
          // warehouse_id: this.ruleForm.warehouse_id,
          // goods_shelf_id: this.ruleForm.goods_shelf_id
        };
        const get_InventoryCount = getInventoryCount(obj_kucun);
        Promise.all([
          get_ProductList,
          get_ModelNumberList,
          get_SpecificationList,
          get_ProductColorList,
          get_InventoryCount,
        ]).then((results) => {
          const [
            productLists,
            ModelNumberLists,
            getSpecificationLists,
            getColorList,
            kucun_nums,
          ] = results;
          if (
            productLists.code === 200 &&
            ModelNumberLists.code === 200 &&
            getSpecificationLists.code === 200 &&
            getColorList.code === 200 &&
            kucun_nums.code === 200
          ) {
            let obj = {
              id: item.id,
              pid_list: this.set_pidlist(item.product_id, item.order_second),
              productList: productLists.data,
              ModelNumberList: ModelNumberLists.data.data,
              SpecificationList: getSpecificationLists.data.data,
              ColorList: getColorList.data,
              kucun_num: kucun_nums.data,
              is_kucun: item.is_kucun,
              pid: item.product_id,
              is_split: item.is_split,
              type_id: item.type_id,
              product_id: item.product_id,
              model_number_id: item.model_number_id,
              specification_id: item.specification_id,
              color_id: item.color_id,
              direction: item.direction,
              num: item.num,
              work_size: item.work_size,
              is_replenishment: item.is_replenishment,
              remark: item.remark,
              chuangtougui_remark: item.chuangtougui_remark,
              chuangbian_remark: item.chuangbian_remark,
              is_del: item.is_del,
              addition_subtraction: item.addition_subtraction,
              brand: item.brand,
              price: item.price,
              xishu: item.xishu,
            };
            this.semi_product.push(obj);
          }
        });
      });
    },
    async get_InventoryCounts_pid(list, id, index, index_pid) {
      let obj = {
        product_id: this.semi_product[index].pid_list[index_pid].product_id,
        color_id: this.semi_product[index].color_id,
        model_number_id: this.semi_product[index].model_number_id,
        specification_id: this.semi_product[index].specification_id,
        // warehouse_id: this.ruleForm.warehouse_id,
        // goods_shelf_id: this.ruleForm.goods_shelf_id
      };
      await getInventoryCount(obj).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].pid_list[index_pid].kucun_num = res.data;
        }
      });

      list.forEach((item) => {
        if (item.id == id) {
          this.semi_product[index].pid_list[index_pid].type_id = item.type_id;
        }
      });
    },
    async get_InventoryCounts(index) {
      let obj = {
        product_id: this.semi_product[index].product_id,
        color_id: this.semi_product[index].color_id,
        model_number_id: this.semi_product[index].model_number_id,
        // specification_id: this.semi_product[index].specification_id,
        // warehouse_id: this.ruleForm.warehouse_id,
        // goods_shelf_id: this.ruleForm.goods_shelf_id
      };
      await getInventoryCount(obj).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].kucun_num = res.data;
        }
      });
    },
    // 客户列表
    getCustomer() {
      getCustomerList({ is_simple: 1 }).then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data;
        }
      });
    },
    ban_warehouse(val) {
      this.cangkulists.forEach((item) => {
        if (item.id == val) {
          this.$nextTick(() => {
            this.huojialist = item.children;
          });
        }
      });
    },
    get_ban_WarehouseList() {
      getWarehouseList().then((res) => {
        if (res.code == 200) {
          this.cangkulists = res.data.data;
        }
      });
    },
    guige_change(val, index) {
      this.semi_product[index].SpecificationList.forEach((item) => {
        if (item.specification_id == val) {
          this.semi_product[index].unit_price = item.price;
        }
      });
    },
    submitadd() {
      this.loading_btn = true;
      this.ruleForm.semi_product = [];
      this.semi_product.forEach((item) => {
        if (item.is_del == 2) {
          let pid_lists = [];
          if (item.pid_list.length > 0 && item.is_split == 1) {
            console.log(item.pid_list);
            item.pid_list.forEach((item) => {
              let objs = {
                id: item.id,
                product_id: item.product_id,
                // model_number_id: item.model_number_id,
                // specification_id: item.specification_id,
                // color_id: item.color_id,
                // direction: item.direction,
                is_needed: item.is_needed,
                // price: item.price,
                num: item.num,
                type_id: item.type_id,
                // work_size: item.work_size,
                is_kucun: item.is_kucun,
                remark: item.remark,
                // addition_subtraction: item.addition_subtraction,
                // brand:item.brand
              };
              pid_lists.push(objs);
            });
          }
          let obj = {
            pid_list: pid_lists,
            type_id: item.type_id,
            product_id: item.product_id,
            model_number_id: item.model_number_id,
            specification_id: item.specification_id,
            color_id: item.color_id ? item.color_id : "",
            direction: item.direction,
            num: item.num,
            is_split: item.is_split,
            pid: item.product_id,
            work_size: item.work_size,
            is_del: item.is_del,
            is_kucun: item.is_kucun,
            remark: item.remark,
            chuangtougui_remark: item.chuangtougui_remark,
            chuangbian_remark: item.chuangbian_remark,
            addition_subtraction: item.addition_subtraction,
            brand: item.brand,
            price: item.price,
            xishu: item.xishu,
          };
          this.ruleForm.semi_product.push(obj);
        }
      });
      return new Promise((resolve, reject) => {
        createOrder(this.ruleForm)
          .then((res) => {
            if (res.code == 200) {
              // loading_btn
              resolve({ success: true });
              if (this.title == "新增订单") {
                this.$message.success("提交成功~");
                this.isProduct = false;
                this.isjietu = false;
                this.$message.success(
                  "提交成功,进入审核流程,审核通过之后在订单列表查看~"
                );
              }
              this.loading_btn = false;
            } else {
              this.loading_btn = false;
            }
          })
          .catch(() => {
            reject("请求失败");
            this.loading_btn = false;
          });
      });
    },
    async submitadd_audit() {
      this.loading_btn = true;
      this.ruleForm.semi_product = [];
      this.semi_product.forEach((item) => {
        if (item.is_del == 2) {
          let pid_lists = [];
          if (item.pid_list.length > 0 && item.is_split == 1) {
            item.pid_list.forEach((item) => {
              let objs = {
                id: item.id,
                product_id: item.product_id,
                // model_number_id: item.model_number_id,
                // specification_id: item.specification_id,
                // color_id: item.color_id,
                // direction: item.direction,
                num: item.num,
                type_id: item.type_id,
                is_needed: item.is_needed,
                // price: item.price,
                // work_size: item.work_size,
                is_kucun: item.is_kucun,
                remark: item.remark,
                // addition_subtraction: item.addition_subtraction,
                // brand:item.brand
              };
              pid_lists.push(objs);
            });
          }
          let obj = {
            pid_list: pid_lists,
            id: item.id,
            type_id: item.type_id,
            product_id: item.product_id,
            model_number_id: item.model_number_id,
            specification_id: item.specification_id,
            color_id: item.color_id ? item.color_id : "",
            direction: item.direction,
            num: item.num,
            work_size: item.work_size,
            is_del: item.is_del,
            is_kucun: item.is_kucun,
            remark: item.remark,
            chuangtougui_remark: item.chuangtougui_remark,
            chuangbian_remark: item.chuangbian_remark,
            is_split: item.is_split,
            pid: item.product_id,
            addition_subtraction: item.addition_subtraction,
            price: item.price,
            xishu: item.xishu,
            brand: item.brand,
          };
          this.ruleForm.semi_product.push(obj);
        }
      });
      return new Promise((resolve, reject) => {
        alertOrder(this.ruleForm)
          .then((res) => {
            if (res.code == 200) {
              resolve({ success: true });
              if (this.title == "新增订单") {
                this.$message.success("提交成功~");
                this.isProduct = false;
                this.isjietu = false;
                this.$message.success(
                  "提交成功,进入审核流程,审核通过之后在订单列表查看~"
                );
              }
              this.loading_btn = false;
            } else {
              this.loading_btn = false;
              reject("请求失败");
            }
          })
          .catch((error) => {
            console.error("请求失败:", error);
            this.loading_btn = false;
            reject(error);
          });
      });
    },
    // 信息审核通过
    shenhe_sub() {
      // 订单审核
      let query = {
        id: this.ruleForm.id,
        status: "1",
        field: this.type,
      };
      auditOrder(query)
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "提交成功",
              type: "success",
            });
            this.isProduct = false;
            this.loading_btn = false;
            this.$emit("getlist");
          }
        })
        .catch(() => {
          this.loading_btn = false;
        });
    },
    async submitadds(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let isValid = true;
          let isValid_pid = true;

          // 使用 some 方法替代 forEach，提高性能
          const hasInvalidItem = this.semi_product.some((item) => {
            if (item.is_del == 2 && item.is_split == 2) {
              if (item.product_id == "") {
                this.$message.error("有产品信息未完善！");
                isValid = false;
                return true; // 停止遍历
              }
              if (item.model_number_id == "") {
                this.$message.error("有型号信息未完善！");
                isValid = false;
                return true; // 停止遍历
              }
            }
            return false;
          });

          if (!hasInvalidItem && isValid && isValid_pid) {
            try {
              if (this.type == "add_order") {
                this.submitadd()
                  .then((res) => {
                    if (res.success) {
                      this.isProduct = false;
                      this.$emit("get_list");
                    }
                  })
                  .catch((error) => {
                    this.loading_btn = false;
                    console.error("请求失败:", error);
                  });
              }
              if (this.type == "set_order") {
                this.submitadd_audit()
                  .then((res) => {
                    if (res.success) {
                      this.shenhe_sub();
                      this.isProduct = false;
                      this.$emit("get_list");
                    }
                  })
                  .catch((error) => {
                    console.error("请求失败111:", error);
                    this.loading_btn = false;
                  });
              }
              if (this.type == "info_status") {
                this.submitadd_audit()
                  .then((res) => {
                    if (res.success) {
                      this.shenhe_sub();
                    }
                  })
                  .catch((error) => {
                    console.error("请求失败111:", error);
                    this.loading_btn = false;
                  });

                // this.shenhe_sub();
              }
              if (this.type == "purchase_status") {
                this.submitadd_audit()
                  .then((res) => {
                    if (res.success) {
                      this.shenhe_sub();
                    }
                  })
                  .catch((error) => {
                    console.error("请求失败111:", error);
                    this.loading_btn = false;
                  });
              }
            } catch (error) {
              this.$message.error("提交失败：" + error.message);
            }
          } else {
            return false;
          }
        } else {
          console.error(
            "表单验证失败，详细信息：",
            this.$refs[formName].errorMessage
          ); // 增加详细的错误信息
          return false;
        }
      });
    },
    model_number_id_change_pid(id, val, index, index_pid) {
      let obj = {
        product_id: id,
        model_number_id: val,
      };
      this.get_InventoryCounts(index);
      getSpecificationList(obj).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].pid_list[index_pid].SpecificationList =
            res.data.data;
          this.semi_product[index].pid_list[index_pid].specification_id = "";
        }
      });
    },
    model_number_id_change(id, val, index) {
      let obj = {
        product_id: id,
        model_number_id: val,
      };
      getSpecificationList(obj).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].SpecificationList = res.data.data;
          this.semi_product[index].specification_id = "";
          this.semi_product[index].unit_price = "";
        }
      });
    },
    get_produccolor(id, index, val) {
      this.semi_product[index].ColorList = [];
      getProductColorList({ product_id: id }).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].ColorList = res.data;
          let that = this;
          setTimeout(() => {
            that.semi_product[index].ColorList.some((item) => {
              if (item.color === val) {
                that.semi_product[index].color_id = item.id;
              }
            });
          }, 300);
        }
      });
    },
    get_produccolor_pids(id, index, index_pid, val) {
      getProductColorList({ product_id: id }).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].pid_list[index_pid].ColorList = [];
          this.semi_product[index].pid_list[index_pid].ColorList = res.data;
          let that = this;
          setTimeout(() => {
            that.semi_product[index].pid_list[index_pid].ColorList.some(
              (item) => {
                if (item.color == val) {
                  that.semi_product[index].pid_list[index_pid].color_id =
                    item.id;
                }
              }
            );
          }, 300);
        }
      });
    },
    get_produccolor_pid(id, index, index_pid) {
      this.semi_product[index].pid_list[index_pid].ColorList = [];
      getProductColorList({ product_id: id }).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].pid_list[index_pid].ColorList = res.data;
        }
      });
    },
    get_producModel(id, index) {
      getModelNumberList({
        product_id: id,
        field_list: "id,model_number",
        is_dropdown: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].ModelNumberList = res.data.data;
        }
      });
    },
    get_producModel_pid(id, index, index_pid) {
      getModelNumberList({
        product_id: id,
        field_list: "id,model_number",
        is_dropdown: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].pid_list[index_pid].ModelNumberList =
            res.data.data;
        }
      });
    },
    product_id_change_pid(val, index, index_pid) {
      this.ModelNumberList = [];
      this.semi_product[index].pid_list[index_pid].specification_id = "";
      this.semi_product[index].pid_list[index_pid].model_number_id = "";
      this.get_producModel_pid(val, index, index_pid);
      this.get_produccolor_pid(val, index, index_pid);
      this.semi_product[index].pid_list[index_pid].productList.forEach(
        (item) => {
          if (item.id == val) {
            this.semi_product[index].pid_list[index_pid].is_replenishment =
              item.is_replenishment;

            if (item.is_replenishment == 1) {
              getWaigouProductKucun({ product_id: val }).then((res) => {
                if (res.code == 200) {
                  this.semi_product[index].pid_list[index_pid].kucun = res.data;
                }
              });
            }
          }
        }
      );
    },
    product_id_change(val, index) {
      this.ModelNumberList = [];
      this.semi_product[index].specification_id = "";
      this.semi_product[index].model_number_id = "";
      this.semi_product[index].is_split = 2;
      this.get_producModel(val, index);
      this.get_produccolor(val, index);
      this.productList.forEach((item) => {
        if (item.id == val) {
          this.semi_product[index].is_replenishment = item.is_replenishment;

          if (item.is_replenishment == 1) {
            getWaigouProductKucun({ product_id: val }).then((res) => {
              if (res.code == 200) {
                this.semi_product[index].kucun = res.data;
              }
            });
          }
        }
      });
    },
    automatic_GenerationSerialNumber() {
      automaticGenerationSerialNumber().then((res) => {
        this.ruleForm.serial_number = res.data;
      });
    },
    inits(String) {
      this.getEmpl();
      // 审核流程
      this.get_OrderAuditList();
      // 订单号
      this.auto_maticGenerationOrderNumber();
      // this.automatic_GenerationSerialNumber();
      // 产品
      this.getproduct();
      // this.getproduct_remark()
      this.getCustomer();
      this.semi_product = [];
      this.get_ban_WarehouseList();

      this.isProduct = true;
      this.type = String;
    },
    auto_maticGenerationOrderNumber() {
      automaticGenerationOrderNumber().then((res) => {
        this.ruleForm.order_number = res.data;
      });
    },
    get_OrderAuditList() {
      getOrderAuditFlow().then((res) => {
        if (res.code == 200) {
          this.AuditList = res.data;
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
          let obj = {
            id: "",
            productList: res.data.data,
            ModelNumberList: [],
            ColorList: [],
            SpecificationList: [],
            product_lists: [],
            kucun_num: 0,
            is_kucun: 2,
            type_id: "",
            is_split: 2,
            pid: "",
            product_id: "",
            model_number_id: "",
            specification_id: "",
            color_id: "",
            direction: "",
            num: 1,
            work_size: "",
            addition_subtraction: "",
            brand: "",
            price: "",
            xishu: 1,
            remark: "",
            chuangtougui_remark: "",
            chuangbian_remark: "",
            is_del: 2,
            pid_list: [],
          };
          this.semi_product.push(obj);
        }
      });
    },
    // 业务员列表
    getEmpl() {
      getYeWuYuanList().then((res) => {
        if (res.code == 200) {
          this.EmployeeList = res.data;
        }
      });
    },
    // 产品列表
    getproduct_remark() {
      // is_simple:1
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList_remark = res.data.data;
          console.log(this.productList_remark);
        }
      });
    },
    add_cailiao() {
      let istrue = true;
      let istrue_pid = true;

      for (let i = 0; i < this.semi_product.length; i++) {
        if (
          this.semi_product[i].is_del == 2 &&
          this.semi_product[i].is_split == 2
        ) {
          if (this.semi_product[i].product_id == "") {
            this.$message.error("请选择产品");
            istrue = false;
            break;
          }
          // if (this.semi_product[i].model_number_id == "") {
          //   this.$message.error("请选择型号");
          //   istrue = false;
          //   break;
          // }
          // if (this.semi_product[i].specification_id == "") {
          //   this.$message.error("请选择规格");
          //   istrue = false;
          //   break;
          // }
        }
      }
      if (istrue & istrue_pid) {
        this.getproduct();
      } else {
        return false;
      }
    },
    del_cailiao(num) {
      this.semi_product[num].is_del = 1;
    },
    add_order_close() {
      this.loading_btn = false;
      this.ruleForm = {
        pay_type: "",
        discount: 0,
        is_fahuo: 2,
        warehouse_id: "",
        terminal_customer: "",
        goods_shelf_id: "",
        serial_number: "",
        order_number: "",
        order_date: "",
        delivery_date: "",
        account_executive_id: "",
        account_executive: "",
        customer_id: "",
        customer: "",
        customer_name: "",
        customer_phone: "",
        received: "",
        emergency_procedure: 1,
        is_replenishment: 2,
        is_stock_up: 2,
        receivables: "",
        remark: "",
        yukuan: "",
        id: "",
        logistics_company: "",
        semi_product: [],
      };
      this.disableds_product = false;
    },
    product_id_type(index, val) {
      getProductList({ type_id: val, is_simple: 1 }).then((res) => {
        if (res.code == 200) {
          this.semi_product[index].productList = res.data;
          this.semi_product[index].product_id = "";
          this.semi_product[index].model_number_id = "";
          this.semi_product[index].color_id = "";
        }
      });
    },
  },
};
</script>

<style scoped>
.bei_zhu_style >>> .el-textarea__inner {
  color: red !important;
}

.list_order {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  place-items: left;
}

.list_order .lis {
  width: 100%;
}

.list_orders {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  place-items: left;
  background: #f5f5f5;
  padding: 10px;
  box-sizing: border-box;
  border-radius: 10px;
  margin-top: 15px;
}

.list_orders .lis {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-form-item >>> .el-input.is-disabled .el-input__inner {
  color: #000 !important;
}
</style>
